/*
 *  @名称：    娜塔丽
 *  @地图：    射手村美发店
 *  @功能：    美发
 *  @作者：    彩虹工作室
 *  @时间：    2016年12月30日
 */

var status = -1;
var beauty = 0;
var hair_Colo_new;
var isSecond = false;
var isAngel;
var sele;
var ct = -1;
function start() {
    isAngel = cm.getBeginner() == 6001;
    /*if (isAngel) {        cm.sendChoiceAngle();        return;    } else {*/        action(1, 0, 0);    //}
}

function action(mode, type, selection) {

    if (mode == 0) {
        cm.dispose();
        return;
    } else if (mode == 1) {
        status++;
    } else {
        status--;
    }

    switch (status) {
        case 0:
            if (isAngel) {
                isSecond = selection != 0;
            }
            cm.sendSimple("我是 #r萬能理髮師 #k愛德華。如果你有#b#v5150052##k或#b#v5151036##k，就來我這裡做頭髮吧!請選擇你要做的項目。\r\n#b#L0#更換髮型（使用萬能高級理髮卡）#l\r\n#L1#染色（使用萬能高級染色卡）#l\r\n#L2#整容大師#l");
            break;
        case 1:
            if (selection == 0) {
                var hair = isSecond ? cm.getPlayer().getSecondHair() : cm.getPlayerStat("HAIR");
                hair_Colo_new = [];
                beauty = 1;

                if (cm.getPlayerStat("GENDER") == 0) {
					for(i = 0;i<=99;i++){
						hair_Colo_new[i] = 30000 + 10 * i;
					}
                    //hair_Colo_new = [30030, 30020, 30000, 30310, 30330, 30060, 30150, 30410, 30210, 30140, 30120, 30200];
                } else {
					for(i = 0;i<=99;i++){
						hair_Colo_new[i] = 31000 + 10 * i;
					}
                    //hair_Colo_new = [31050, 31040, 31000, 31150, 31310, 31300, 31160, 31100, 31410, 31030, 31080, 31070,31430];
                }
                for (var i = 0; i < hair_Colo_new.length; i++) {
                    hair_Colo_new[i] = hair_Colo_new[i] + (hair % 10);
                }
                hair_Colo_new = cm.getCanHair(hair_Colo_new);
                cm.askAvatar("我能將你煥然一新。慢慢挑選你想要的髮型吧~這裡可是有將近八十幾種呢!", hair_Colo_new, 5150119, isSecond != 0);
            } else if (selection == 1) {
                var hairColor = isSecond ? cm.getPlayer().getSecondHair() : cm.getPlayerStat("HAIR");
                var currenthaircolo = Math.floor((hairColor / 10)) * 10;
                hair_Colo_new = [];
                beauty = 2;

                for (var i = 0; i < 8; i++) {
                    hair_Colo_new[i] = currenthaircolo + i;
                }
                hair_Colo_new = cm.getCanHair(hair_Colo_new);
                cm.askAvatar("我能將你煥然一新。慢慢挑選你想要的髮色吧~", hair_Colo_new, 5150119, isSecond != 0);
            }else if(selection == 2){
				cm.dispose();
				cm.openNpc(9201148);
				return;
			}
            break;
        case 2:
			sele = selection
            if (hair_Colo_new.length == 0) {
                cm.sendOk("出現未知錯誤");
				cm.dispose();
            } else if (beauty == 1) {
                if (cm.setAvatar(5150119, hair_Colo_new[selection], isSecond) == 1) {
                    cm.sendNext("享受你的新髮型吧!!!");
					cm.dispose();
                } else {
                    cm.sendYesNo("您沒有可用的會員卡。是否想#b消耗 #r980 #b抵用券#k直接購買使用？");
                }
            } else {

                if (cm.setAvatar(5150119, hair_Colo_new[selection], isSecond) == 1) {
                    cm.sendNext("享受你的新髮色吧!!!");
					cm.dispose();
                } else {
					cm.sendYesNo("您沒有可用的會員卡。是否想#b消耗 #r980 #b點券#k直接購買使用？");
                }
            }
            break;
        case 3:
            if (cm.getChar().getCSPoints(2) >= 980) {
                ct = 2;
            }
            if (ct != -1) {
                if (cm.gainNX(ct, -980)) {
                    cm.gainItem(5150119, 1);
					if (cm.setAvatar(5150119, hair_Colo_new[sele], isSecond) == 1) {
						cm.sendNext("享受你的新造型吧!!!");
						cm.dispose();
					} else {
						cm.sendOk("發生未知錯誤!");
						cm.dispose();
					}
                } else {
                    cm.sendOk("您好像沒有足夠的點券/抵用券!");
                    cm.dispose();
                }
            } else {
                beauty = 5150119;
            }
			break;
        default:
            cm.dispose();
            break;
    }
}